package com.admin.config;

import com.admin.domain.media.MediaProperties;
import com.admin.domain.media.QiniuUploader;
import com.foxinmy.weixin4j.mp.WeixinProxy;
import com.foxinmy.weixin4j.payment.WeixinPayProxy;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
@EnableConfigurationProperties(MediaProperties.class)
public class Weixin4jConfig {
    @Bean
    public WeixinProxy getWeixinProxy() {
        return new WeixinProxy();
    }

    @Bean
    public WeixinPayProxy getWeixinPayProxy() {
        return new WeixinPayProxy();
    }

    @Bean
    public ThreadPoolTaskExecutor taskExecutor() {
        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
        taskExecutor.setCorePoolSize(10);
        taskExecutor.setMaxPoolSize(50);
        taskExecutor.setQueueCapacity(100);
        taskExecutor.setKeepAliveSeconds(100);
        return taskExecutor;
    }

    @Bean
    @ConfigurationProperties
    public QiniuUploader qiniuUploader(MediaProperties properties) {
        return new QiniuUploader(properties);
    }
}
